import pandas as pd

# 读取数据
data = pd.read_csv('data/car_1000.txt', header=None)

# 映射字典
mappings = {
    'buying': {'vhigh': 0, 'high': 1, 'med': 2, 'low': 3},
    'maint': {'vhigh': 0, 'high': 1, 'med': 2, 'low': 3},
    'doors': {'2': 0, '3': 1, '4': 2, '5more': 3},
    'persons': {'2': 0, '4': 1, 'more': 2},
    'lug_boot': {'small': 0, 'med': 1, 'big': 2},
    'safety': {'low': 0, 'med': 1, 'high': 2},
    # 'class': {'unacc': 0, 'acc': 1, 'good': 2, 'vgood': 3}
}

# 列名
columns = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety', 'class']

# 应用映射
for col, mapping in zip(columns, mappings.values()):
    #data[col] = data[columns.index(col)].map(mapping)
    data[columns.index(col)] = data[columns.index(col)].map(mapping)

# 打印数值化后的数据
print(data)

# 保存数值化后的数据
data.to_csv('data/car_1000_numeric.csv', index=False, header=False)